package com.accloud.service;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import java.util.Objects;

public class Topic {
    public static final String CLASS = "zc-class";
    private static final String PREFIX = "zc-";
    public static final String PROPERTY = "zc-property";
    public static final String STATUS = "zc-status";
    public static final String WARNING = "zc-warning";
    private final JsonElement key;
    public final transient String subDomain;
    private final String type;

    Topic(String subDomain2, String type2, JsonElement key2) {
        this.subDomain = subDomain2;
        this.type = type2;
        this.key = key2;
    }

    Topic(String subDomain2, String type2, String key2) {
        this(subDomain2, type2, new Gson().toJsonTree(key2));
    }

    public String getType() {
        return this.type;
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Topic topic = (Topic) o;
        if (!Objects.equals(this.subDomain, this.subDomain) || !this.type.equals(topic.type)) {
            return false;
        }
        return this.key.equals(topic.key);
    }

    public int hashCode() {
        return ((((this.subDomain != null ? this.subDomain.hashCode() : 0) * 31) + this.type.hashCode()) * 31) + this.key.hashCode();
    }

    public String toString() {
        return "Topic{subDomain='" + this.subDomain + "', type='" + this.type + "', key=" + this.key + '}';
    }

    public static Topic customTopic(String subDomain2, String type2, String key2) {
        if (!isPreserved(type2)) {
            return new Topic(subDomain2, type2, key2);
        }
        throw new IllegalArgumentException("Type \"" + type2 + "\" preserved for internal use");
    }

    public static boolean isPreserved(String type2) {
        return type2.toLowerCase().startsWith(PREFIX);
    }
}
